# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:android)

platform :android do
  desc "Runs all the tests"
  lane :test do
    gradle(task: "test")
  end

  desc "Build debug and test APK for screenshots"
  lane :build_for_screenshots do
    gradle(
      task: 'clean'
    )
    build_android_app(
      task: 'assemble',
      build_type: 'Debug'
    )
    build_android_app(
      task: 'assemble',
      build_type: 'AndroidTest'
    )
  end

  desc "Screenshots on multiple devices"
  lane :screenshots do
    def screenshots_on_device(device_name, device_type)
      emulators = adb(command: 'devices').scan(/emulator-\d+/)
      emulator = emulators.find {|e| adb(serial: e, command: 'emu avd name').start_with?(device_name + "\r\n")}
      if emulator == nil
        UI.error('Emulator not running: ' + device_name)
      else
        capture_android_screenshots(
          specific_device: emulator,
          device_type: device_type,
          launch_arguments: "device_type " + device_type
        )
      end
    end

    screenshots_on_device('Pixel_4_API_31_G', 'phone')
    screenshots_on_device('Nexus_7_API_32_G', 'sevenInch')
    screenshots_on_device('Nexus_10_API_32_G', 'tenInch')
  end
end
